cmake_minimum_required(VERSION 3.16)
project(WuKong VERSION 1.0 LANGUAGES CXX)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 设置可执行文件输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
# 设置动态库的输出目录
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
# 设置静态库的输出目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
# 设置链接库目录
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
# 包含头文件目录
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

# 查找依赖
find_package(Boost 1.71 REQUIRED COMPONENTS system thread filesystem regex)
find_package(OpenSSL REQUIRED)

# ======================================================
# 构建动态库 libmylightercore.so
# ======================================================
add_library(wukongcore SHARED
    src/config.cpp
    src/lighter.cpp
    src/ws_connection.cpp
    src/https_connection.cpp
    src/http_connection_pool.cpp
    src/binance.cpp
    src/str_utils.cpp
)

# 链接库依赖
target_link_libraries(wukongcore
    Boost::system
    Boost::thread
    Boost::filesystem
    Boost::regex
    OpenSSL::SSL
    OpenSSL::Crypto
    yaml-cpp
    signer-amd64
    pthread
)

# ======================================================
# 构建可执行文件
# ======================================================
add_executable(main src/main.cpp)
add_executable(market_shm_reader tests/market_shm_reader.cpp)
add_executable(order_shm_writer tests/order_shm_writer.cpp)
add_executable(trade_shm_reader tests/trade_shm_reader.cpp)
add_executable(quant_test tests/quant_test.cpp)
add_executable(parquet_reader tests/parquet_reader.cpp)
add_executable(parquet_writer tests/parquet_writer.cpp)

# ======================================================
# 可执行文件链接动态库
# ======================================================
target_link_libraries(main wukongcore)
target_link_libraries(market_shm_reader wukongcore)
target_link_libraries(order_shm_writer wukongcore)
target_link_libraries(trade_shm_reader wukongcore)
target_link_libraries(quant_test signer-amd64)
target_link_libraries(parquet_reader parquet arrow)
target_link_libraries(parquet_writer parquet arrow)

# ======================================================
# Debug 默认启用
# ======================================================
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug)
endif()
